export const format = (time) => {
  let ymd = ''
  let mouth = (time.getMonth() + 1) >= 10 ? (time.getMonth() + 1) : ('0' + (time.getMonth() + 1))
  let day = time.getDate() >= 10 ? time.getDate() : ('0' + time.getDate())
  ymd += time.getFullYear() + '-' // 获取年份。
  ymd += mouth + '-' // 获取月份。
  ymd += day // 获取日。

  return ymd // 返回日期。
}

export const getAllDate = (start, end) => {

  let dateArr = []
  let db = new Date(start)
  let de = new Date(end)
  console.log(db);
  let unixDb = db.getTime()
  let unixDe = de.getTime()
  let stamp
  const oneDay = 24 * 60 * 60 * 1000;
  for (stamp = unixDb; stamp <= unixDe;) {
    dateArr.push(format(new Date(parseInt(stamp))))
    stamp = stamp + oneDay
  }
  return dateArr
}
//周一到周五判断标准 默认加班时间startDate 20:30 
const overtime = (s, startDate) => { //0否1是
  if (!s) { //s没有值返回0（没有加班）
    return 0
  }
  let time = s.replaceAll(':', '')
  //每四位组成一个时间
  let size = time.length / 4 //长度截取次数
  let ifjiaban = 0
  for (let r = 0; r < size; r++) {
    let dakatime = time.substring(r * 4, r * 4 + 4)
    if (dakatime >= startDate && dakatime < 2400) {
      ifjiaban = 1
    }
  }
  return ifjiaban
}
//周六周日
const overtimeWeekend = (s) => {
  // if (!s) { //s没有值返回0（没有加班）
  //   return 0
  // }
  let time = s.replaceAll(':', '')
  let size = time.length/4
  let ifjiaban = 0
  for (let r = 0; r < size; r++) {
    let dakatime = time.substring(r * 4, r * 4 + 4)
    console.log(dakatime)

    if ((dakatime > 830 )&& dakatime < 2400) {
      ifjiaban = 1
    }
  }
  console.log(ifjiaban)
  return ifjiaban
}
//判断凌晨00：00-08：30有无打卡
const dawn = (s) => {
  let ifjiaban = 0
  //
  let time = s.replaceAll(':', '');
  let size = time.length/4
  for (let r = 0; r < size; r++) {
    let dakatime = time.substring(r * 4, r * 4 + 4)
    console.log(dakatime)

    if ((dakatime > 0 )&& dakatime < 530) {
      ifjiaban = 1
    }
  }
  return ifjiaban
}

export const daka  = {overtime , overtimeWeekend , dawn}

//根据数据生成excle
export const creatExcle = () => {
  var filename = "file.xlsx"; //文件名称
  var data = [
    [1, 2, 3],
    [true, false, null, "sheetjs"],
    ["foo", "bar", new Date("2014-02-19T14:30Z"), "0.3"],
    ["baz", null, "qux"]
  ]; //数据，一定注意需要时二维数组
  var ws_name = "Sheet1"; //Excel第一个sheet的名称
  var wb = XLSX.utils.book_new(),
    ws = XLSX.utils.aoa_to_sheet(data);
  XLSX.utils.book_append_sheet(wb, ws, ws_name); //将数据添加到工作薄
  XLSX.writeFile(wb, filename); //导出Excel
}
export const changeWeek = (s) => {
  switch (s) {
    case 0:
      return "星期日"
    case 1:
      return "星期一"
    case 2:
      return "星期二"
    case 3:
      return "星期三"
    case 4:
      return "星期四"
    case 5:
      return "星期五"
    case 6:
      return "星期六"
    default:
  }
}
let b = 1
export const jsono = [{
    "项目组__12__月份加班考勤表（加班至晚9点以后）": "客户简称：",
    列头2: "邮储行",
    列头3: "",
    列头4: "项目号：",
    列头5: "190777-53",
    列头6: "",
    列头7: "",
    列头8: "",
    列头9: "",
    列头10: "",
    列头11: "",
    列头12: "",
    列头13: "",
    列头14: "",
  },
  {
    "项目组__12__月份加班考勤表（加班至晚9点以后）": "客户简称：",
    列头2: "邮储行",
    列头3: "",
    列头4: "项目号：",
    列头5: "190777-53",
  },
  {
    "项目组__12__月份加班考勤表（加班至晚9点以后）": "客户简称：",
    列头2: "邮储行",
    列头3: "",
    列头4: "项目号：",
    列头5: "190777-53",
  },
  {
    "项目组__12__月份加班考勤表（加班至晚9点以后）": "项目经理签字",
    列头6: "分软经理签字",
    列头11: "客户签字",
  },
  {
    "项目组__12__月份加班考勤表（加班至晚9点以后）": "",
  },
  {
    "项目组__12__月份加班考勤表（加班至晚9点以后）": "日期",
    列头2: "星期",
    列头3: "合计人数",
    列头4: "合计金额",
    列头5: "加班人员名单",
  }
 
]
export const jsono1 = [{
  "项目组__12__月份加班考勤表（加班至晚9点以后）": "客户简称：",
  列头2: "邮储行",
  列头3: "",
  列头4: "项目号：",
  列头5: "190777-53",
  列头6: "",
  列头7: "",
  列头8: "",
  列头9: "",
  列头10: "",
  列头11: "",
  列头12: "",
  列头13: "",
  列头14: "",
},
{
  "项目组__12__月份加班考勤表（加班至晚9点以后）": "客户简称：",
  列头2: "邮储行",
  列头3: "",
  列头4: "项目号：",
  列头5: "190777-53",
},
{
  "项目组__12__月份加班考勤表（加班至晚9点以后）": "客户简称：",
  列头2: "邮储行",
  列头3: "",
  列头4: "项目号：",
  列头5: "190777-53",
},
{
  "项目组__12__月份加班考勤表（加班至晚9点以后）": "项目经理签字",
  列头6: "分软经理签字",
  列头11: "客户签字",
},
{
  "项目组__12__月份加班考勤表（加班至晚9点以后）": "",
},
{
  "项目组__12__月份加班考勤表（加班至晚9点以后）": "日期",
  列头2: "星期",
  列头3: "合计人数",
  列头4: "合计金额",
  列头5: "加班人员名单",
}

]